﻿using System;
using fastCSharp;
using fastCSharp.code.cSharp;

namespace diantou.dataModel.path
{
    /// <summary>
    /// 用户URL
    /// </summary>
    public struct user
    {
        /// <summary>
        /// 匿名用户
        /// </summary>
        private static readonly string anonymous = "javascript:fastCSharp.Void();";
        /// <summary>
        /// 用户标识
        /// </summary>
        public int Id;
        /// <summary>
        /// 查询字符串
        /// </summary>
        public string Query
        {
            get
            {
                return "userId=" + Id.toString();
            }
        }
        /// <summary>
        /// 查询字符串
        /// </summary>
        public string AndQuery
        {
            get
            {
                return "&userId=" + Id.toString();
            }
        }
        /// <summary>
        /// 我的关注更新(首页)
        /// </summary>
        public string NewFocus
        {
            get
            {
                return Id == 0 ? anonymous : "/focus.html";
            }
        }
        /// <summary>
        /// 我的私信
        /// </summary>
        public string Message
        {
            get
            {
                return Id == 0 ? anonymous : "/message.html";
            }
        }
        /// <summary>
        /// 基本资料设置
        /// </summary>
        public string Setting
        {
            get
            {
                return Id == 0 ? anonymous : "/setting/index.html";
            }
        }
        /// <summary>
        /// 自我描述设置
        /// </summary>
        public string DepictSetting
        {
            get
            {
                return Id == 0 ? anonymous : "/setting/description.html";
            }
        }
        /// <summary>
        /// 密码设置
        /// </summary>
        public string PasswordSetting
        {
            get
            {
                return Id == 0 ? anonymous : "/setting/account.html";
            }
        }
        /// <summary>
        /// 通知状态设置
        /// </summary>
        public string NoticeSetting
        {
            get
            {
                return Id == 0 ? anonymous : "/setting/notice.html";
            }
        }
        /// <summary>
        /// 我的黑名单
        /// </summary>
        public string Blacklist
        {
            get
            {
                return Id == 0 ? anonymous : "/blacklist.html";
            }
        }
        /// <summary>
        /// 我的通知
        /// </summary>
        public string Notice
        {
            get
            {
                return Id == 0 ? anonymous : "/notice.html";
            }
        }
        /// <summary>
        /// 二维码地址
        /// </summary>
        public string WinxinQrCode
        {
            get
            {
                return Id == 0 ? null : "//" + path.domain.Default.StaticFileDomain + "/upload/weixin/" + (Id >> 12).toString() + "/" + (Id & ((1 << 12) - 1)).toString() + ".png";
            }
        }
        /// <summary>
        /// 我的私信
        /// </summary>
        public string EnterpriseMessage
        {
            get
            {
                return "/enterprise/message.html";
            }
        }
        /// <summary>
        /// 企业信息设置
        /// </summary>
        public string EnterpriseSetting
        {
            get { return "/enterprise/setting.html"; }
        }
        /// <summary>
        /// 企业通知
        /// </summary>
        public string EnterpriseNotice
        {
            get
            {
                return "/enterprise/notice.html";
            }
        }
        /// <summary>
        /// 企业账户
        /// </summary>
        public string EnterpriseAccount
        {
            get
            {
                return "/enterprise/account.html";
            }
        }
        /// <summary>
        /// 获取用户URL
        /// </summary>
        /// <param name="name">名称/类型</param>
        /// <returns>用户URL</returns>
        private webView.hashUrl get(string name)
        {
            return new webView.hashUrl { Path = "/user/" + name + ".html", Query = Query };
        }
        /// <summary>
        /// 用户首页
        /// </summary>
        public webView.hashUrl Index
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("index");
            }
        }
        /// <summary>
        /// 关注用户的人
        /// </summary>
        public webView.hashUrl Focus
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("focus");
            }
        }
        /// <summary>
        /// 用户关注的人
        /// </summary>
        public webView.hashUrl FocusUser
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("focusUser");
            }
        }
        /// <summary>
        /// @提到用户的
        /// </summary>
        public webView.hashUrl UserMention
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("mention");
            }
        }
        /// <summary>
        /// 用户的问题
        /// </summary>
        public webView.hashUrl Question
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("question");
            }
        }
        /// <summary>
        /// 用户的回答
        /// </summary>
        public webView.hashUrl Answer
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("answer");
            }
        }
        /// <summary>
        /// 用户关注的问题
        /// </summary>
        public webView.hashUrl FocusQuestion
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("focusQuestion");
            }
        }
        /// <summary>
        /// 用户关注的话题
        /// </summary>
        public webView.hashUrl FocusTopic
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("focusTopic");
            }
        }
        /// <summary>
        /// 用户参与的话题
        /// </summary>
        public webView.hashUrl JoinTopic
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("joinTopic");
            }
        }
        /// <summary>
        /// 用户的编辑日志
        /// </summary>
        public webView.hashUrl Log
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("log");
            }
        }
        /// <summary>
        /// 发送消息
        /// </summary>
        public webView.hashUrl UserMessage
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : new webView.hashUrl { Path = "/messageList.html", Query = Query };
            }
        }
        /// <summary>
        /// 我的收藏夹
        /// </summary>
        public webView.hashUrl Favorite
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("favorite");
            }
        }
        /// <summary>
        /// 收藏动态
        /// </summary>
        public webView.hashUrl NewFavorite
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("newFavorite");
            }
        }
        /// <summary>
        /// 用户关注的收藏夹
        /// </summary>
        public webView.hashUrl FocusFavorite
        {
            get
            {
                return Id == 0 ? new webView.hashUrl { Path = anonymous } : get("focusFavorite");
            }
        }
        /// <summary>
        /// 用户收到的回答邀请
        /// </summary>
        public webView.hashUrl UserReceiveInvite
        {
            get
            {
                if (Id == 0) return new webView.hashUrl { Path = anonymous };
                webView.hashUrl index = get("invite");
                return new webView.hashUrl { Path = index.Path, Query = index.Query + "&isInvite=1" };
            }
        }
        /// <summary>
        /// 用户OJ主页
        /// </summary>
        public webView.hashUrl OnlineJudge
        {
            get
            {
                if (Id == 0) return new webView.hashUrl { Path = anonymous };
                return new webView.hashUrl { Path = "/onlineJudge/user.html", Query = Query };
            }
        }
        /// <summary>
        /// 用户的提交记录
        /// </summary>
        public webView.hashUrl OnlineJudgeSubmit
        {
            get { return Id == 0 ? new webView.hashUrl { Path = anonymous } : new webView.hashUrl { Path = problem.SubmitList, Query = Query }; }
        }
        /// <summary>
        /// 用户的勋章
        /// </summary>
        public webView.hashUrl OnlineJudgeMedal
        {
            get { return Id == 0 ? new webView.hashUrl { Path = anonymous } : new webView.hashUrl { Path = "/onlineJudge/medalList.html", Query = Query }; }
        }
        /// <summary>
        /// 用户在问题下的提交记录
        /// </summary>
        /// <param name="problemId"></param>
        /// <returns></returns>
        public webView.hashUrl OnlineJudgeProblemSubmit(int problemId)
        {
            return new webView.hashUrl { Path = problem.SubmitList, Query = Query + new diantou.dataModel.path.problem { Id = problemId }.AndQuery };
        }
        /// <summary>
        /// 用户的提交记录
        /// </summary>
        private webView.hashUrl judgeStatus
        {
            get
            {
                return new webView.hashUrl { Path = problem.JudgeStatus, Query = Query };
            }
        }
        /// <summary>
        /// 用户关注的题目
        /// </summary>
        public webView.hashUrl OnlineJudgeFocusProblem
        {
            get
            {
                if (Id == 0) return new webView.hashUrl { Path = anonymous };
                return new webView.hashUrl { Path = problem.Focus, Query = Query };
            }
        }
        /// <summary>
        /// 用户比赛主页
        /// </summary>
        public webView.hashUrl Contest
        {
            get
            {
                if (Id == 0) return new webView.hashUrl { Path = anonymous };
                return new webView.hashUrl { Path = "/contest/user.html", Query = Query };
            }
        }
        /// <summary>
        /// 用户比赛的提交记录
        /// </summary>
        public webView.hashUrl ContestSubmit
        {
            get { return Id == 0 ? new webView.hashUrl { Path = anonymous } : new webView.hashUrl { Path = "/contest/userSubmitList.html", Query = Query }; }
        }
        
        /// <summary>
        /// 账户充值
        /// </summary>
        public string Payment
        {
            get
            {
                return Id == 0 ? anonymous : "/payment.html";
            }
        }
        /// <summary>
        /// 第三方登录邮件验证连接
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string SetEmail(long code)
        {
            return "index/SetEmail?code=" + number.toHex16((ulong)code) + AndQuery;
        }
        /// <summary>
        /// 注册验证连接
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetRegiter(long code, bool isEnterprise)
        {
            string path = "index/Register?code=" + number.toHex16((ulong)code) + AndQuery;
            if (isEnterprise) path += "&isEnterprise=1";
            return path;
        }
        /// <summary>
        /// 重置密码验证连接
        /// </summary>
        /// <param name="email"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetPassword(string email, long code, bool isEnterprise)
        {
            string path = "index/GetPassword?code=" + number.toHex16((ulong)code) + "&email=" + email;
            if (isEnterprise) path += "&isEnterprise=1";
            return path;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private static string andType(string type)
        {
            return "&type=" + type;
        }
    }
}
